package 练习02_多线程穷举法破解密码;

import java.util.List;

/**
 * @ClassName: LogThread
 * @Author: AllenSun
 * @Date: 2022/3/18 下午9:34
 */
public class LogThread extends Thread {
    private boolean found = false;
    private List<String> pwdList;

    public LogThread(List<String> pwdList) {
        this.pwdList = pwdList;
        this.setDaemon(true);//设置守护线程，当其他线程执行完，只剩下守护线程时，整个任务结束
        //守护线程主要用在做日志，性能统计等工作
    }

    @Override
    public void run() {
        while (true) {
            while (pwdList.isEmpty()) {
                //确保线程安全，也可以直接使用锁
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            String pwd = pwdList.remove(0);
            System.out.println("穷举法本次生成的密码是："+pwd);
        }
    }
}
